﻿using System;
using System.Data.Entity;
using System.Data.SQLite;
using ORM.EF.Models;

namespace ORM.EF.Context
{
    public class DBContext : DbContext
    {
        public DBContext(string databaseName = "SqlliteEF6")
            : base(databaseName)
        {

        }
        //protected override void OnModelCreating(DbModelBuilder modelBuilder)
        //{
        //    System.Data.SQLite.SQLiteConnectionStringBuilder connstr = new System.Data.SQLite.SQLiteConnectionStringBuilder(this.Database.Connection.ConnectionString);
        //    string path = AppDomain.CurrentDomain.BaseDirectory + connstr.DataSource;
        //    System.IO.FileInfo fi = new System.IO.FileInfo(path);
        //    if (System.IO.File.Exists(fi.FullName) == false)
        //    {
        //        if (System.IO.Directory.Exists(fi.DirectoryName) == false)
        //        {
        //            System.IO.Directory.CreateDirectory(fi.DirectoryName);
        //        }
        //        SQLiteConnection.CreateFile(fi.FullName);

        //        connstr.DataSource = path;
        //        //connstr.Password = "admin";//设置密码，SQLite ADO.NET实现了数据库密码保护
        //        using (SQLiteConnection conn = new SQLiteConnection(connstr.ConnectionString))
        //        {
        //            string sql = @" CREATE TABLE User (
        //                               Id INTEGER PRIMARY KEY AUTOINCREMENT,
        //                               Name varchar (20),
        //                               Time timestamp,
        //                               Data blob,
        //                               Val real,
        //                               TestE int);";
        //            conn.Open();
        //            SQLiteCommand cmd = new SQLiteCommand(sql, conn);
        //            cmd.ExecuteNonQuery();
        //        }
        //    }
        //    //添加创建代码
        //    //modelBuilder.Configurations.Add(new Blog());
        //}
        public DbSet<Project> Projects { get; set; }
        public DbSet<Supplier> Suppliers { get; set; }
        public DbSet<Part> Parts { get; set; }
        public DbSet<SupplyRecord> SupplyRecords { get; set; }
        public DbSet<Warehouse> Warehouses { get; set; }
        public DbSet<Worker> Workers { get; set; }
        public DbSet<WarehouseRecord> WarehouseRecords { get; set; }
        public DbSet<Title> Titles { get; set; }
    }
}